import { getPayableShipmentDetailInfoApi } from "@/api/financialManagement/payableManagement/payableDetails";
import { reactive, ref } from "vue";

export default function InitHook() {
  const formState = reactive<PayableDetails.FeeInfo>({
    waybillId: "",
    waybillNum: "",
    pickupCity: "",
    customerShortName: "",
    customerName: "",
    bizName: "",
    outWarehouseBrokerName: "",
    depositTime: "",
    itemNumber: 0,
    channelName: "",
    agentChannelName: "",
    customsDeclarationType: "",
    customsTaxesType: "",
    declaredValue: 0,
    systemAgentSettlementWeight: 0,
    destination: "",
    warehouseCode: "",
    settlementWeight: 0,
    importAgentSettlementWeight: 0,
    zipCode: "",
    squaresNumber: 0,
    actualWeight: 0,
    innerRemark: "",
    productName: "",
    materialQualityName: "",
    volumeWeight: 0,
    customerRemark: "",
    grossProfit: 0,
    productRatio: "",
    kgProfit: 0,
    receivableAmountSum: 0,
    receivableFeeList: [],
    payableAmountSum: 0,
    payableFeeList: [],
    adjustCostSum: 0
  });
  const loading = ref<boolean>(false);
  const dialogOpts = reactive<Base.DialogOpts>({
    title: "修改送货仓库",
    width: "720px",
    type: 1,
    passData: {},
    component: "",
    visible: false
  });
  const drawerOpts = reactive<Base.DrawerOpts>({
    title: "修改送货仓库",
    width: "720px",
    type: 1,
    passData: {},
    component: "",
    visible: false
  });
  // 有报价ID
  const init = (waybillId: string) => {
    loading.value = true;
    return getPayableShipmentDetailInfoApi(waybillId)
      .then((res: any) => {
        const { code, data } = res;
        if (code === 200) {
          Object.assign(formState, data);
        }
      })
      .finally(() => {
        loading.value = false;
      });
  };
  return {
    formState,
    loading,
    dialogOpts,
    drawerOpts,
    init
  };
}
